/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package HumanCentredSystemDesign;
import java.util.ArrayList;
/**
 *
 * @author Martin
 */
public class Borrower {
             
    String libraryMemberID;
    String forename;
    String surname;
    String emailAddress;

    public Borrower(String _libraryMemberID, String _forename, String _surname, String _emailAddress){
        libraryMemberID = _libraryMemberID;
        forename = _forename;
        surname = _surname;
        emailAddress = _emailAddress;
    }
    public Borrower(){};
 
    public String getBorrowerID() {
        return libraryMemberID;
    }    
    public String getBorrowerForename(){
        return forename;
    }
    public String getBorrowerSurname(){
        return this.surname;
    }
    public String getBorrwerEmailAddress(){
        return emailAddress;
    }
    
    //Database Accessing Methods
    public ArrayList<Loan> getLoans(){
        try{
            ArrayList<Loan> loanList = new ArrayList<Loan>();
            Connect conn = new Connect();
            conn.establishConnection();
            loanList = conn.getBorrowersLoans(this);
            return loanList;
        }
        catch(Exception err){
            System.out.println("Error Retrieving Borrower Loans: "  + err.toString());
            return null;
        }
        
    }
    public ArrayList<Reservation> getReservations(){
        ArrayList<Reservation> reservationList;
        Connect conn = new Connect();
        conn.establishConnection();
        reservationList = conn.getReservationsFromDatabase("",this.libraryMemberID);
        return reservationList;
    }   
    
    public boolean hasFines(){
        
        boolean fines = false;
        ArrayList<Loan> myLoans= this.getLoans();
        for (Loan l : myLoans){
            if(l.isOverdue() == true)
            {
                fines = true;
            }
        }
        return fines;
    }
    

    @Override
    public String toString(){
            String sb = new String();
            for (Loan s : this.getLoans())
                {
                    sb =  sb +"\n" + (s.toString())  ; 
                }
        return getBorrowerID() + " " + this.forename +" "+ this.surname +" "+ getBorrwerEmailAddress() +" "+ sb;
    }
    
   
    
}
